﻿using System;
using System.Windows;
using Microsoft.Phone.Controls;
using ClientMobile.SSVService;
namespace googlemaps
{
    public partial class Connexion : PhoneApplicationPage
    {
        public Connexion()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Service1SoapClient serv = new Service1SoapClient();
            serv.ConnxionChauffeurCompleted += serv_ConnxionChauffeurCompleted;
            serv.ConnxionChauffeurAsync(textBox1.Text, passwordBox1.Password);
        }

        void serv_ConnxionChauffeurCompleted(object sender, ConnxionChauffeurCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                Singleton s = Singleton.Instance;
                s.Chauff = e.Result;
                Service1SoapClient serv = new Service1SoapClient();
                serv.envoyerNotiCompleted += new EventHandler<envoyerNotiCompletedEventArgs>(serv_envoyerNotiCompleted);
                serv.envoyerNotiAsync("Connexion de Chauffeur :"+s.Chauff.Nom+" "+s.Chauff.Prenom,s.Chauff.id_chauffeur,0);
               
                

            }
            else
            {
                MessageBox.Show("Veillez-Verifier Vos parametres de connexion");
            }
        }

        void serv_envoyerNotiCompleted(object sender, envoyerNotiCompletedEventArgs e)
        {
            if (e.Result)
            {
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }



        private void button2_Click(object sender, RoutedEventArgs e)
        {
           // App.Quit();
        }

    }
}